import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from './../views/home/index.vue'//首页
import House from './../views/house/index.vue'//店铺
import Cart from './../views/cart/index.vue'//购物车
import User from './../views/user/index.vue'//我的
import NotFound from './../views/error/NotFound.vue'


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) { 
  return originalPush.call(this, location).catch((err) => err)
}
Vue.use(VueRouter)

// 定义路由规则

const routes = [
    { // 路由重定向
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        name: 'home',
        component: Home

    },
    {
        path: '/house',
        name: 'house',
        component: House
    },
    {
        path: '/cart',
        name: 'cart',
        component: Cart
    },

    {
        path: '/user',
        name: 'user',
        component: User
    },
    { // 404页面, 路由匹配是从上到下
        path: '**',
        name: 'notfound',
        component: NotFound
    }


]

// 生成路由
const router = new VueRouter({
    mode: 'hash',
    routes
})

// 暴露模块
export default router